<template>
  <div class="todo-app">
    <div class="title">Todo App</div>

    <div class="todo-form">
      <input
        v-model="value"
        type="text"
        class="todo-input"
        placeholder="Add a todo"
      />
      <div 
        @click="add" 
        class="todo-button" 
        :class="{ disabled: value.trim() === '' }"
        :disabled="value.trim() === ''"
      >
        Add Todo
      </div>
    </div>

    <div class="todo-list">
      <div
        v-for="(item, index) in list"
        :key="index"
        :class="[item.isCompleted ? 'completed' : 'item']"
      >
        <div>
          <input v-model="item.isCompleted" type="checkbox" />
          <span class="name">{{ item.value }}</span>
        </div>

        <div @click="del(index)" class="del">✖</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
const list = ref([
  { value: '吃饭', isCompleted: true },
  { value: '睡觉', isCompleted: false },
  { value: '打豆豆', isCompleted: false },
])

function add() {
  if (value.value.trim() === '') {
    return
  }
  list.value.push({
    value: value.value,
    isCompleted: false,
  })

  value.value = ''
}

function del(index) {
  list.value.splice(index, 1)
}
</script>

<style scoped>
.todo-app {
  box-sizing: border-box;
  margin: 40px auto;
  padding: 40px;
  width: 80%;
  min-width: 600px;
  max-width: 1000px;
  background: #ffffff;
  border-radius: 15px;
  box-shadow: rgba(149, 157, 165, 0.3) 0px 4px 12px;
}

.title {
  text-align: center;
  font-size: 36px;
  font-weight: 700;
  color: #333;
  margin-bottom: 40px;
}

.todo-form {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 0 40px;
}

.todo-button {
  width: 140px;
  height: 50px;
  border-radius: 8px;
  text-align: center;
  background: linear-gradient(
    to right,
    #6c63ff,
    #3071b3
  );
  color: #fff;
  line-height: 50px;
  cursor: pointer;
  font-size: 16px;
  user-select: none;
  transition: all 0.3s ease;
}

.todo-button:hover:not(.disabled) {
  background: linear-gradient(
    to right,
    #3071b3,
    #6c63ff
  );
  transform: translateY(-2px);
}

.todo-button.disabled {
  background: #cccccc;
  cursor: not-allowed;
  transform: none;
}

.todo-input {
  padding: 15px 20px;
  border-radius: 8px;
  border: 1px solid #dfe1e5;
  outline: none;
  width: 70%;
  font-size: 16px;
  transition: border-color 0.3s ease;
}

.todo-input:focus {
  border-color: #6c63ff;
}

.todo-list {
  padding: 0 40px;
  max-height: 60vh;
  overflow-y: auto;
}

.item, .completed {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin: 15px 0;
  padding: 20px 25px;
  border-radius: 10px;
  box-shadow: rgba(149, 157, 165, 0.1) 0px 4px 12px;
  transition: all 0.3s ease;
  background: #f9f9f9;
}

.item:hover, .completed:hover {
  box-shadow: rgba(149, 157, 165, 0.3) 0px 8px 24px;
  transform: translateY(-2px);
}

.item input[type="checkbox"],
.completed input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-right: 15px;
  cursor: pointer;
}

.name {
  font-size: 16px;
  margin-left: 10px;
}

.del {
  color: #ff4d4f;
  font-size: 20px;
  cursor: pointer;
  transition: color 0.3s ease;
  padding: 5px 10px;
}

.del:hover {
  color: #a8071a;
}

.completed {
  background: #f0f7f0;
}

.completed .name {
  text-decoration: line-through;
  color: #999;
}

@media (max-width: 768px) {
  .todo-app {
    width: 95%;
    min-width: auto;
    padding: 20px;
  }

  .todo-form {
    padding: 0 20px;
  }

  .todo-list {
    padding: 0 20px;
  }

  .todo-input {
    width: 65%;
  }

  .todo-button {
    width: 100px;
  }
}
</style> 